package org.example.controller.post;


import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.example.dao.commom.Result;
import org.example.dao.commom.ResultCode;
import org.example.dao.dto.post.ReportDto;
import org.example.dao.entity.post.PReport;
import org.example.service.post.ReportService;
import org.example.skytool.commom.ParamUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 22449
 */
@RestController
@RequestMapping("/post")
@CrossOrigin
public class ReportController {

    //TODO 新增
    /**
     * 发起举报(用户)
     */
    @PostMapping("addReport")
    public Result addReport(@RequestBody PReport pReport){
        String due = pReport.getDue();
        Long linkId = pReport.getLinkId();
        String type = pReport.getType();
        String kind = pReport.getKind();

        ParamUtil.StringParam(due,type,kind);
        ParamUtil.LongParam(linkId);

        ReportDto pReport1 = reportService.addReport(due,linkId,type,kind);
        return new Result(ResultCode.SUCCESS,pReport1);
    }

    //TODO 查询
    /**
     * 根据type和status查询举报(管理)
     */
    @PostMapping("selectReportByTypeAndStatus/{limit}/{start}")
    public Result selectReportByTypeAndStatus(@RequestBody PReport pReport,
                                     @PathVariable("limit")Long limit,
                                     @PathVariable("start")Long start){
        String type = pReport.getType();
        String status = pReport.getStatus();
        String kind = pReport.getKind();

        ParamUtil.StringParam(type,status,kind);

        IPage<ReportDto> list = reportService.selectReportByTypeAndStatus(type,status,kind,limit,start);
        return new Result(ResultCode.SUCCESS,list);
    }

    /**
     * 获取类型列表(用户)
     */
    @PostMapping("selectTypeList")
    public Result selectTypeList(){
        List<String> list = reportService.selectTypeList();
        return new Result(ResultCode.SUCCESS,list);
    }

    //TODO 更新

    /**
     * 修改举报状态(管理)
     */
    @PostMapping("updateReportStatus")
    public Result updateReportStatus(@RequestBody PReport pReport){
        Long id = pReport.getId();
        String status = pReport.getStatus();

        ParamUtil.LongParam(id);
        ParamUtil.StringParam(status);

        status = reportService.updateReportStatus(id,status);
        return new Result(ResultCode.SUCCESS,status);
    }

    //TODO 删除

    /**
     * 删除举报(管理)
     */
    @PostMapping("deleteReport")
    public Result deleteReport(@RequestBody PReport pReport){
        Long id  = pReport.getId();

        ParamUtil.LongParam(id);

        reportService.deleteReport(id);
        return new Result(ResultCode.SUCCESS,null);
    }

    @Resource
    private ReportService reportService;

}
